﻿using Prism.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SyntacticSugar;

namespace SPW.Infrastructure.Repositorys
{
    /// <summary>
    /// 事件聚合仓储
    /// </summary>
    public class EventAggregatorRepository
    {
        public EventAggregatorRepository(IEventAggregator _eventAggregator = null)
        {
            if (eventAggregator.IsNullOrEmpty()) eventAggregator = new EventAggregator();
            else eventAggregator = _eventAggregator;
        }

        public IEventAggregator eventAggregator;
        public static EventAggregatorRepository eventRepository = null;

        /// <summary>
        /// 获取单实例
        /// </summary>
        /// <returns></returns>
        public static EventAggregatorRepository GetInstance()
        {
            if (eventRepository == null)
            {
                eventRepository = new EventAggregatorRepository();
            }
            return eventRepository;
        }

        /// <summary>
        /// 设置单实例
        /// </summary>
        /// <param name="_eventAggregator"></param>
        public static void SetInstance(IEventAggregator _eventAggregator)
        {
            eventRepository = new EventAggregatorRepository(_eventAggregator);
        }
    }
}
